Page({
  data: {
    serviceInfo: {},
    date: '',
    time: '',
    address: '',
    phone: '',
    remark: '',
    today: ''
  },

  onLoad(options) {
    const today = new Date();
    const todayStr = `${today.getFullYear()}-${String(today.getMonth() + 1).padStart(2, '0')}-${String(today.getDate()).padStart(2, '0')}`;
    this.setData({ today: todayStr });

    // 模拟获取服务详情
    this.setData({
      serviceInfo: {
        id: options.id || 1,
        title: '家庭保洁服务',
        desc: '专业保洁团队，提供全方位家庭保洁服务',
        price: '80',
        image: 'https://dummyimage.com/1200x600/eeeeee/aaaaaa.png&text=service'
      }
    });
  },

  onDateChange(e) {
    this.setData({ date: e.detail.value });
  },

  onTimeChange(e) {
    this.setData({ time: e.detail.value });
  },

  onAddressInput(e) {
    this.setData({ address: e.detail.value });
  },

  onPhoneInput(e) {
    this.setData({ phone: e.detail.value });
  },

  onRemarkInput(e) {
    this.setData({ remark: e.detail.value });
  },

  onSubmit() {
    const { date, time, address, phone } = this.data;
    
    if (!date) {
      wx.showToast({ title: '请选择服务日期', icon: 'none' });
      return;
    }
    if (!time) {
      wx.showToast({ title: '请选择服务时间', icon: 'none' });
      return;
    }
    if (!address) {
      wx.showToast({ title: '请输入服务地址', icon: 'none' });
      return;
    }
    if (!phone) {
      wx.showToast({ title: '请输入联系电话', icon: 'none' });
      return;
    }

    wx.showLoading({ title: '提交中...' });
    
    // 模拟提交
    setTimeout(() => {
      wx.hideLoading();
      wx.showModal({
        title: '预约成功',
        content: '您的预约已提交，服务人员将尽快与您联系',
        showCancel: false,
        success: () => {
          wx.navigateBack();
        }
      });
    }, 1000);
  }
})
